/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.lang.reflect.Array;
import java.lang.reflect.Constructor;

/**
 * <p>Project: jse2303 - Reflect01</p>
 * <p>Powered by webrx On 2023-07-28 11:02:27</p>
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Reflect01 {
    public static void main(String[] args) throws Exception {
        //1
        Class<String> c1 = String.class;

        //2
        Class<?> c2 = Class.forName("java.lang.String");

        //3
        Class<?> c3 = "hello".getClass();

        //int[] 数组返回类
        Class<int[]> c4 = int[].class;

        System.out.println(c1 == c2);
        System.out.println(c3 == c2);
        System.out.println(c3 == c1);

        //建立对象
        Constructor<?>[] cs = c1.getConstructors();
        Constructor<String> con = c1.getConstructor(String.class);
        String s = con.newInstance("hello");
        System.out.println(s);

        int[] o = (int[]) Array.newInstance(int.class, 3);
        o[2] = 3;
        int[] aa = new int[3];
        aa[2] = 3;
        System.out.println(Array.get(o, 0));
        System.out.println(o[2]);

        //System.out.println(ccs.length);

    }
}
